const mongoose = require("mongoose");
// mongoose.connect("mongodb://localhost/test",{useMongoClient:true});
mongoose.connect("mongodb://localhost:27017/test", { useNewUrlParser: true });
mongoose.Promise = Promise;

const Product = mongoose.model("Product",{
  pname:{
    type:String,
    match:[/^[\u4e00-\u9fa5A-Za-z0-9-_]{1,20}$/,"产品名称不得为空，只能使用中英文，数字，下划线，减号，且长度应在20字以内。"]
  },
  pimgsrc:{
    type:String,
    required:[true,"请上传相关产品图片。"],
  },
  pprice:{
    type:String,
    match:[/^￥[0-9]{1,6}(.[0-9]{0,2})?$/,"产品价格不得为空，且在￥0.01~￥999999.99之间。"]
  },
  pdescription:{
    type:String,
    required:[true,"产品详情不得为空。"],
    maxlength:[100,"产品详情长度在100字以内。"]
  },
  createTime:Date,
  updateTime:Date,
  S_Time:String,    //updateTime格式化为"yyyy-MM-dd hh:mm:ss"形式，以便在各浏览器端统一显示
  accessNum:Number
});

module.exports = Product;
